﻿/**
*任务分配
*/
Chenxin.UI.TaskForm=Chenxin.extend(Chenxin.UI.FormCommon,{
	actionUrl:'service/TaskDispenseInfo.ashx',
	id:'taskWin',
	renderTo:'jqm_task',
	title:'分配任务',
	jqmWidth:700,
	defBBtn:true,
	initFormValidator:function(){
        _this = this;
	    
	    //开始时间
		$("#startAddTime").focus(function(){
            WdatePicker({oncleared:function(){$(this).blur();},onpicked:function(){$(this).blur();}})
        }).formValidator({validatorgroup:this.id,
            onshow:"请输入开始日期!",
            onfocus:"请输入开始日期!",
            oncorrect:" "
        }).inputValidator({
            empty: { leftempty: false, rightempty: false, emptyerror: "开始日期不能为空!" }, 
            type:"date",
            onerror:"开始日期不能为空!"
        });
        
		//结束时间
		$("#endAddTime").focus(function(){
            WdatePicker({oncleared:function(){$(this).blur();},onpicked:function(){$(this).blur();}})
        }).formValidator({validatorgroup:this.id,
            onshow:"请输入结束日期!",
            onfocus:"请输入结束日期!",
            oncorrect:" "
        }).inputValidator({
            empty: { leftempty: false, rightempty: false, emptyerror: "结束日期不能为空!" }, 
            type:"date",
            onerror:"结束日期不能为空!"
        }).functionValidator({
	        fun: function(val, elem) {
	            if ($("#startAddTime").val() != "" && $("#endAddTime").val() != "") {
	                var d1 = new Date(Date.parse($("#startAddTime").val().replace(/-/g, "/")));
	                var d2 = new Date(Date.parse($("#endAddTime").val().replace(/-/g, "/")));
	                if ((d1.getTime() - d2.getTime()) > 0) {
	                    return false;
	                } else {
	                    return true;
	                }
	            }
	        }, onerror: "开始时间大于结束时间!"
	    });
	    //主题验证
	    $("#txtTitle").formValidator({ validatorgroup:this.id,
            onshow:"请输入主题!",
            onfocus:"请输入主题!",
            oncorrect:" "
        }).inputValidator({
            min: 1, 
            empty: { leftempty: false, rightempty: false, emptyerror: "主题不能为空!" }, 
            onerror: "主题不能为空!"
        });
        //描述验证
	    $("#txtdescribe").formValidator({ validatorgroup:this.id,
            onshow:"请输入描述!",
            onfocus:"请输入描述!",
            oncorrect:" "
        }).inputValidator({
            min: 1, 
            onerror: "描述不能为空!"
        }).functionValidator({
            fun:function(val,elem){
                if(val.replace(/^\ +|\ +$/ig,"") != ""){
                    return true;
                }else{
                    return "描述不能为空!"
                }
            }, onerror: "描述不能为空!"
        });
	},
	createForm:function(){
		// return formCommon.houseTaskForm('task');
		return Chenxin.FormCommon.houseTaskForm('task');
	},
	initEvent:function(){
		var _this=this;
		$('#task_Save').live('click',function(){
		    _this.op="add";
			_this.save();
		});
		$('#task_Reset').live('click',function(){
		    var model=_this.getParam();
		    var _data={};
		    _data.relatedCaption = model.relatedCaption;//小区地址
            _data.relatedCode = model.relatedCode;//房源编号
            _data.AddPerson = model.AddPerson;//所属人
            _data.AddDepart = model.AddDepart;//所属部门
			//_this.reset();
			_this.fitData(_data);

		});
		$('#task_Close').live('click',function(){
			_this.hide();
		});
	},
	createComboList:function(){	
	    //接收人部门
		var receiverDepart = new Chenxin.UI.StructCombo({
            param: { op: 'getcontroldeparts' },
            containerId: '#task_divDepartment',
            inModelType: 'all',
            name:'ReceiverDepartId',
			txtModelName:"ReceiverDepart",
			tbxWidth:90,
			autoLoad:true,
			required:true,
            onSelected: function() {
				if(this.getValue()==this.defVal){
					receiver.clearItems();
				}else{
				    receiver.param.fatherid=this.getValue();
				    receiver.reload();
				}
            }
        });
        //接收人
        var receiver = new Chenxin.UI.StructCombo({
            autoLoad: false,
            param: { op: 'getemployee'},
            inModelType: 'all',
            name:'taskReceiverId',
			txtModelName:"taskReceiver",
			tbxWidth:90,
            containerId: '#task_divTaskUser',
            required:true
        });	
	    //任务类型
		var contactType=new Chenxin.UI.ParameterCombo({
			name:'TaskType',
			containerId:'#task_divTaskType',
			inModelType:'txt',
			key:'Task.Type',
			tbxWidth:90,
			required:true
		});
		return [receiverDepart,receiver,contactType];
	},
	saveSucc:function(){

    },
	initComponent:function(){
		Chenxin.UI.TaskForm.superclass.initComponent.call(this);
	}
});
    /**
    *@description 任务分配表单
    *@comboIdPrefix DIV下拉框和提交按钮前缀
    */
Chenxin.FormCommon.houseTaskForm=function(comboIdPrefix) {
        return '<table class="tbl_f" width="100%"><tbody><tr><th style="width:110px; height:25px;">房源编号：</th><td style="width:300px;"><input type="text" name="relatedCode" class="inputbox_n" readonly="readonly" style="width:120px"/></td><th style="width:80px; height:25px;">小区地址：</th><td style="width:320px;"><input type="text" name="relatedCaption" class="inputbox_n" readonly="readonly" style="width:120px"/></td></tr><tr><th>所属人员：</th> <td id ="f_belongPerson"><input type="text" name="AddPerson" class="inputbox_n" readonly="readonly" style="width:120px"/></td><th>所属门店：</th> <td id ="f_belongTdepartment"><input type="text" name="AddDepart" class="inputbox_n" readonly="readonly" style="width:120px"/></td></tr><tr><th>接收人部门：</th><td><div id="' + comboIdPrefix + '_divDepartment" style="z-index:910; margin-right: 5px;" class="SelectWrapSingle"></div></td><th>接收人：</th><td><div id="' + comboIdPrefix + '_divTaskUser" style="z-index:909; margin-right: 5px;" class="SelectWrapSingle"></div></td></tr><tr><th>开始时间：</th><td><input style="width:120px;" name="TaskBeginDay" class="inputbox_n fl" id="startAddTime" type="text" onclick="WdatePicker({position:{left:this.getBoundingClientRect().left+1,top:this.getBoundingClientRect().top+22}});"  readonly="readonly" /><div id="startAddTimeTip" style="float: left; margin-left: 5px; width: 90; height: 26px; line-height: 26px; text-align: left;" class="fl"></div></td><th>结束时间：</th><td><input style="width:120px;" name="TaskEndDay"  class="inputbox_n fl" id="endAddTime" type="text" onclick="WdatePicker({position:{left:this.getBoundingClientRect().left+1,top:this.getBoundingClientRect().top+22}});"  readonly="readonly" /><div id="endAddTimeTip" style="float: left; margin-left: 5px; width: 90; height: 26px; line-height: 26px; text-align: left;" class="fl"></div></td></tr><tr><th>类型：</th><td colspan="3"><div id="' + comboIdPrefix + '_divTaskType" style="z-index:908; margin-right: 5px;" class="SelectWrapSingle"></div></td></tr><tr><th>主题：</th><td colspan="3"><input type="text" id="txtTitle" name="Title" class="inputbox_n" style="width:470px; float: left;" /><div id="txtTitleTip" style="float: left; margin-left: 5px; width: 90; height: 26px; line-height: 26px; text-align: left;" class="fl"></div></td></tr><tr><th>描述：</th><td colspan="3"><textarea id="txtdescribe" name="Description" cols="80" rows="10" class="textarea_n" style="float: left; width: 465px; height: 100px; padding:5px;"></textarea><div id="txtdescribeTip" style="float: left; margin-left: 5px; width: 90; height: 26px; line-height: 26px; text-align: left;" class="fl"></div></td></tr></tbody></table>'
};